package com.archstoday.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.archstoday.R;
import com.archstoday.entity.CommentFromEntity;
import com.archstoday.utils.ToolUtils;
import com.archstoday.view.RoundedImageView;
import com.base.utils.ImageUtil;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 用户评论页面列表适配器-我回复的
 */
public class CommentFromMeAdapter extends BaseAdapter {

    private Context mContext;
    private List<CommentFromEntity.DataBean> mData;

    public CommentFromMeAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<CommentFromEntity.DataBean> data) {
        mData = data;
        notifyDataSetChanged();
    }

    public void addDat(List<CommentFromEntity.DataBean> data) {
        mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mData == null) {
            return 0;
        }
        return mData.size();
    }

    @Override
    public CommentFromEntity.DataBean getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_comment_from_me, null);
            holder.headIcon = (CircleImageView) view.findViewById(R.id.item_head_icon);
            holder.nameTv = (TextView) view.findViewById(R.id.item_name_tv);
            holder.timeTv = (TextView) view.findViewById(R.id.item_time_tv);
            holder.commentTv = (TextView) view.findViewById(R.id.item_comment_tv);
            holder.headImg = (RoundedImageView) view.findViewById(R.id.item_img);
            holder.typeTv = (TextView) view.findViewById(R.id.item_type_tv);
            holder.contentTv = (TextView) view.findViewById(R.id.item_content_tv);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        holder.nameTv.setText(mData.get(i).getComment().getUserName());
        holder.timeTv.setText(ToolUtils.getCreatTime
                (String.valueOf(mData.get(i).getComment().getCreateTime())));
        holder.commentTv.setText(mData.get(i).getComment().getCommentText());
        holder.typeTv.setText(mData.get(i).getArticle().getLabel());
        holder.contentTv.setText(mData.get(i).getArticle().getTitle());

        ImageUtil.setCropBitmap(mContext, holder.headImg,
                mData.get(i).getArticle().getImgs(), R.mipmap.default_icon);

        return view;
    }

    class Holder {
        CircleImageView headIcon;
        TextView nameTv, timeTv, commentTv;
        RoundedImageView headImg;
        TextView typeTv, contentTv;
    }
}